dojo.ready(function() {
    document.title = 'Carregando departamentos... - Criar professor - D.A.R. - Vinipsmaker labs';

    service.getDepartamentos()
    .addCallback(function(result) {
        var buffer = '';
        result.forEach(function(element) {
            buffer += '<option value="'
                + element._id
                + '">'
                + decodeURI(element.nome) + ' (' + element._id + ')'
                + '</option>';
        });
        document.getElementById('departamento').innerHTML += buffer;

        document.title = 'Criar professor - D.A.R. - Vinipsmaker labs';
    })
    .addErrback(onErrback);
});

function onSubmit()
{
    document.title = 'Criando professor... - D.A.R. - Vinipsmaker labs';
    service.addProfessor(encodeURI(document.getElementById('nome').value),
                         document.getElementById('departamento').value)
    .addCallback(function(result) {
        document.getElementById('main').innerHTML
        += '<p>Professor <a href="/professor.html#' + result._id + '">'
        + decodeURI(result.nome)
        + '</a> criado com sucesso</p>';
        document.title = 'Criar professor - D.A.R. - Vinipsmaker labs';
    })
    .addErrback(onErrback);
    return false;
}